// *****************************************************
// Aitrox Information Technology
// http://www.proxima-ai.com
// Copyright 2021 Aitrox. All rights reserved.
//
// Filename: diskstatus_linux.go
// CreateDate: 2023-06-08
// Author: zjp
// Description: 磁盘使用情况具体实现
// ******************************************************
package service

import (
	"syscall"
	"usplatformserver/internal/model"
)

/**
 * @brief 获取磁盘使用情况
 * @param path-磁盘路径
 * @return 磁盘状态，错误信息
 */
func (svc *Service) DiskUsage(path string) (model.DiskStatus, error) {
	var disk model.DiskStatus
	fs := syscall.Statfs_t{}
	err := syscall.Statfs(path, &fs)
	if err != nil {
		return disk, err
	}
	disk.All = fs.Blocks * uint64(fs.Bsize)
	disk.Free = fs.Bfree * uint64(fs.Bsize)
	disk.Used = disk.All - disk.Free
	return disk, nil
}
